layui.use(['form','layer','jquery','element','laypage'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        element = layui.element,
        $ = layui.jquery;

 /*   $(".loginBody .seraph").click(function(){
        layer.msg("这只是做个样式，至于功能，你见过哪个后台能这样登录的？还是老老实实的找管理员去注册吧",{
            time:5000
        });
    })*/



    //登录按钮
    form.on("submit(login)",function(data){
        var btn = $(this);
        btn.text("登录中...").attr("disabled","disabled").addClass("layui-disabled");
        $.post("/loginController/Login",data.field,function (rs) {
            btn.text("登录").attr("disabled",false).removeClass("layui-disabled");
            var data = rs.data;
            if (data.identity === 'user'){
                if (data.consumer != null) {
                    layer.msg("登录成功,即将进入首页!");
                    setTimeout(function () {
                        location.href = '/sys/user';
                    },500)

                } else{
                    layer.msg("用户名或密码错误,登录失败!");
                }
            } else if (data.identity === 'admin') {
                if (data.superuser != null) {
                    layer.msg("登录成功,即将进入首页!");
                    setTimeout(function () {
                        location.href = '/sys/admin';
                    },500)

                } else{
                    layer.msg("用户名或密码错误,登录失败!");
                }
            } else{
                if (data.serviceman != null) {
                    layer.msg("登录成功,即将进入首页!");
                    setTimeout(function () {
                        location.href = '/sys/serviceman';
                    },500)

                } else{
                    layer.msg("用户名或密码错误,登录失败!");
                }
            }
        });
        return false;
    });

    //注册按钮
    $(".register").on('click',function () {
        var index = layer.open({
            title:"注册",
            type:2,
            area:['30%','60%'],
            content:'../static/page/register.html',
            success: function (layero, index) {//参数绑定
                setTimeout(function(){
                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
    })

    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })

})
